package com.zis.auction.controller;

import com.zis.auction.model.Essay;
import com.zis.auction.service.IEssayInter;
import com.zis.core.SearchParams;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by wangshen 2018/1/12
 */
@RestController
@RequestMapping("/api/auction/essay")
public class EssayController {

    @Autowired
    private IEssayInter essayInter;


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public PageQuery<Essay> findByPage(@RequestBody SearchParams params) throws Exception {
        return essayInter.findByPage(params);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String insert(HttpServletRequest request, @RequestBody Essay essay) throws Exception {
        essay.setCreateUser(request.getAttribute("code").toString());
        return essayInter.insert(essay);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public String update(HttpServletRequest request, @RequestBody Essay essay) throws Exception {
        essay.setUpdateUser(request.getAttribute("code").toString());
        return essayInter.update(essay);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String delete(@PathVariable("id") String id) throws Exception{
        return essayInter.delete(id);
    }

    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Essay select(@PathVariable("id") String id) throws Exception{
        return essayInter.selectById(id);
    }

}
